<template>
	<u-tabbar :value="current" inactiveColor="#707070" activeColor="#000" :fixed="true" :placeholder="true"
		:safeAreaInsetBottom="true">
		<u-tabbar-item @click="gotonav" v-for="(item,index) in list" :key="index" :text="item.name">
			<image class="icon" slot="active-icon" :src="item.iconSel"></image>
			<image class="icon" slot="inactive-icon" :src="item.icon"></image>
		</u-tabbar-item>
	</u-tabbar>
</template>

<script>
	export default {
		name: "tabBar",
		data() {
			return {
				list: [{
						name: '主页',
						iconSel: '/static/img/tabbar/home_sel.png',
						icon: '/static/img/tabbar/home_nor.png',
						path: '/pages/home/index',
					},
					{
						name: '订单列表',
						iconSel: '/static/img/tabbar/order_sel.png',
						icon: '/static/img/tabbar/order_nor.png',
						path: '/pages/order/index',
					},
					{
						name: '经营分析',
						iconSel: '/static/img/tabbar/data_sel.png',
						icon: '/static/img/tabbar/data_nor.png',
						path: '/pages/data/index',
					},
					{
						name: '采购',
						iconSel: '/static/img/tabbar/cart.png',
						icon: '/static/img/tabbar/cart_nor.png',
						path: '/pages/cart/index',
					},
					{
						name: '我的',
						iconSel: '/static/img/tabbar/member_sel.png',
						icon: '/static/img/tabbar/member_nor.png',
						path: '/pages/member/index',
					}
				]
			};
		},
		computed: {

			current() {
				let currentIndex = 0;
				let pages = getCurrentPages();
				let fullpath = '/' + pages[pages.length - 1].route;
				this.list.map((item, idx) => {
					if (fullpath == item.path) {
						currentIndex = idx;
					}
				})
				return currentIndex || 0;
			}


		},
		created() {
			var role = uni.getStorageSync("role");
			console.info("===role===" + role);
			if (role == '商家') {
				this.list = [{
						name: '主页',
						iconSel: '/static/img/tabbar/home_sel.png',
						icon: '/static/img/tabbar/home_nor.png',
						path: '/pages/home/index',
					},
					{
						name: '订单列表',
						iconSel: '/static/img/tabbar/order_sel.png',
						icon: '/static/img/tabbar/order_nor.png',
						path: '/pages/order/index',
					},
					{
						name: '经营分析',
						iconSel: '/static/img/tabbar/data_sel.png',
						icon: '/static/img/tabbar/data_nor.png',
						path: '/pages/data/index',
					},
					{
						name: '采购',
						iconSel: '/static/img/tabbar/cart.png',
						icon: '/static/img/tabbar/cart_nor.png',
						path: '/pages/cart/index',
					},
					{
						name: '我的',
						iconSel: '/static/img/tabbar/member_sel.png',
						icon: '/static/img/tabbar/member_nor.png',
						path: '/pages/member/index',
					}
				]
			} else if (role == '代理商') {
				this.list = [{
						name: '主页',
						iconSel: '/static/img/tabbar/home_sel.png',
						icon: '/static/img/tabbar/home_nor.png',
						path: '/pages/home/agent',
					},
					{
						name: '店铺列表',
						iconSel: '/static/img/tabbar/order_sel.png',
						icon: '/static/img/tabbar/order_nor.png',
						path: '/pages/agent/list',
					},

					{
						name: '我的',
						iconSel: '/static/img/tabbar/member_sel.png',
						icon: '/static/img/tabbar/member_nor.png',
						path: '/pages/member/index',
					}
				]
			} else if (role == '员工') {
				this.list = [{
						name: '主页',
						iconSel: '/static/img/tabbar/home_sel.png',
						icon: '/static/img/tabbar/home_nor.png',
						path: '/pages/clean/clear',
					},

					{
						name: '包厢列表',
						iconSel: '/static/img/tabbar/order_sel.png',
						icon: '/static/img/tabbar/order_nor.png',
						path: '/pages/room/tabIndex',
					},

					{
						name: '我的',
						iconSel: '/static/img/tabbar/member_sel.png',
						icon: '/static/img/tabbar/member_nor.png',
						path: '/pages/member/index',
					}
				]
			} else if (role == '助教') {
				this.list = [{
						name: '主页',
						iconSel: '/static/img/tabbar/home_sel.png',
						icon: '/static/img/tabbar/home_nor.png',
						path: '/pages/job/index',
					},

					{
						name: '订单列表',
						iconSel: '/static/img/tabbar/order_sel.png',
						icon: '/static/img/tabbar/order_nor.png',
						path: '/pages/job/list',
					},

					{
						name: '我的',
						iconSel: '/static/img/tabbar/member_sel.png',
						icon: '/static/img/tabbar/member_nor.png',
						path: '/pages/member/index',
					}
				]
			} else if (role == '投资人') {
				this.list = [{
						name: '主页',
						iconSel: '/static/img/tabbar/home_sel.png',
						icon: '/static/img/tabbar/home_nor.png',
						path: '/pages/home/invest',
					},

					{
						name: '营收列表',
						iconSel: '/static/img/tabbar/order_sel.png',
						icon: '/static/img/tabbar/order_nor.png',
						path: '/pages/data/investList',
					},

					{
						name: '我的',
						iconSel: '/static/img/tabbar/member_sel.png',
						icon: '/static/img/tabbar/member_nor.png',
						path: '/pages/member/index',
					}
				]
			}

		},
		methods: {
			gotonav(index) {

				console.info(this.list);
				if (index == this.current) {
					return;
				}
				uni.reLaunch({
					url: this.list[index].path
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.icon {
		width: 56rpx;
		height: 56rpx;
	}
</style>